<template>
  <div class="list-container">
    <div class="back-btn" >
      <ArrowLeftOutlined @click="back" class="back-icon" />
    </div>
    <div class="songList-info">
      <div class="item-info">
        <a-avatar
          shape="square"
          :size="64"
          :src="getPic(compState?.songList.pic)"
        >
          <template #icon v-if="!compState?.songList.pic">
            <UserOutlined />
          </template>
        </a-avatar>
      </div>
      <div class="info-box">
        <div>{{ compState?.songList.title }}</div>
        <div>{{ compState?.songList.style }}</div>
        <div>{{ compState?.songList.introduction }}</div>
      </div>
    </div>
    <div class="songs-container">
      <songsShow :songs="state.songs" :name="compState?.songList.title"></songsShow>
    </div>
  </div>
</template>

<script setup lang="ts">
import {
  reactive,
  toRefs,
  ref,
  computed,
  onMounted,
  defineAsyncComponent,
  shallowRef,
  useAttrs,
} from "vue";
import type { Ref } from "vue";
import { getSongListSongs } from "@/api/api.ts";
import type { songListType,songListStateType } from "@/types/pageTypes/songList.ts";
const compState: Ref<songListStateType | null | undefined> = defineModel();
import useStore from "@/pinia/index.ts";
const { user } = useStore();
const state = reactive({
  songs:[]
});
const getPic = (pic: string | undefined): string => {
  return import.meta.env.VITE_APP_BASE_SERVER + pic;
};
const getSongs = (): void => {
  let userId = user.userInfo.id ? user.userInfo.id : 99999999;
  let songListId: number | undefined = compState.value?.songList.id;
  if (songListId && userId) {
    getSongListSongs(userId, songListId).then(result => {
      if(result.data?.length){
        state.songs = result.data
      }
    });
  }
};

const back = ()=>{
  if(compState.value)
  compState.value.page = "list"
}
onMounted(()=>{
  getSongs()
})
</script>

<style scoped lang="less">
.list-container {
  height:100%;
  display: flex;
  flex-direction: column;
  .back-btn{
    display:flex;
    flex-direction: row-reverse;
    padding: 10px 10px 0;
    .back-icon{
      font-size: 20px;
    }
  }
  .songList-info {
    padding: 10px;
    display: flex;
    justify-content: space-between;
    .info-box {
      margin-left: 20px;
      flex: 1;
      display: flex;
      flex-direction: column;
      text-align: left;
    }
  }
  .songs-container{
    flex:1;
    overflow: hidden;
  }
}
</style>
